<?php
require_once(FWS_DIR_LIB.'core/ModelAndView.class.php');
require_once(FWS_DIR_MODEL_DAO.'newsmodeldao.class.php');
require_once(FWS_DIR_MODEL.'newsmodel.class.php');
require_once(FWS_DIR_MODEL.'flashmodel.class.php');
require_once(FWS_DIR_MODEL_DAO.'eventmodeldao.class.php');
require_once(FWS_DIR_MODEL.'eventmodel.class.php');

class newsMultiActionController {

	var $_newsmodeldao;
	var $_eventmodeldao;

	function newsMultiActionController() {
		$this->_newsmodeldao = new NewsModelDao();
		$this->_eventmodeldao = new EventModelDao();
		mysql_connect(FWS_DBDOMAIN,FWS_DBUSER,FWS_DBPASS);
		mysql_select_db(FWS_DBNAME);
	}

	function list_action() {
		$mv = new ModelAndView();
		/*if(!isset($_SESSION['news'])) {
			//echo $_SESSION['news'].' findAllNews</br>';
			$news = $this->_newsmodeldao->findAllNews(1,'SYSDATE()','SYSDATE()');
			$_SESSION['news'] = $news;
		}*/
		$mv->addToModel(0, $this->_newsmodeldao->findAllNews(1,'SYSDATE()','SYSDATE()'));
		$mv->setView('news_list.tpl');
		mysql_close();
		return $mv;
	}

	function archive_action() {
		$mv = new ModelAndView();
		$mv->addToModel(0, $this->_newsmodeldao->findArchive());
		$mv->setView('news_list.tpl');
		mysql_close();
		return $mv;
	}
	
	function insert_action() {
		$mv = new ModelAndView();
		$this->_newsmodeldao->insertNews(new NewsModel($_POST));
		return $this->adminlist_action();
	}

	function update_action() {
		$mv = new ModelAndView();
		$this->_newsmodeldao->updateNews(new NewsModel($_POST));
		return $this->adminlist_action();
	}
	
	function delete_action() {
		$mv = new ModelAndView();
		$this->_newsmodeldao->deleteNews(get("id"));
		return $this->adminlist_action();
	}


	function detail_action() {
		$mv = new ModelAndView();
		$mv->addToModel(0, $this->_newsmodeldao->selectNews($_GET["id"]));
		$mv->setView('news_detail.tpl');
		mysql_close();
		return $mv;
	}
	
	function form_action() {
		$mv = new ModelAndView();
		$mv->addToModel(0,$this->_eventmodeldao->findAllEvent());
		if(is_numeric(get("id"))) $mv->addToModel(1,$this->_newsmodeldao->selectNews(get("id")));
		$mv->setView('news_form.tpl');
		mysql_close();
		return $mv;
	}
	
	function adminlist_action() {
		$mv = new ModelAndView();
		$mv->addToModel(0, $this->_newsmodeldao->findAllNewsForAdmin());
		$mv->setView('adminnews_list.tpl');
		mysql_close();
		return $mv;
	}

}

?>